package com.xxx.car.web.admin;

import com.github.pagehelper.PageInfo;
import com.xxx.car.entity.vo.request.ReqRefundAdminQuery;
import com.xxx.car.entity.vo.response.RespRefundDetail;
import com.xxx.car.service.TravelAppealService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;

/**
 * Created by yxj on 17/6/26.
 */
@Controller
@RequestMapping("/admin/refund")
public class AdminRefundController {

	@Autowired
	TravelAppealService travelAppealService;

	@RequestMapping(value = "/")
	public String refundList(Model model, @ModelAttribute ReqRefundAdminQuery query) {
		PageInfo pageInfo = travelAppealService.queryRefundAdminList(query);
		HashMap map = (HashMap) travelAppealService.totalRefundAmountAndRefundCount();
		//获得当前页
		model.addAttribute("pageNum", pageInfo.getPageNum());
		//获得一页显示的条数
		model.addAttribute("pageSize", pageInfo.getPageSize());
		//是否是第一页
		model.addAttribute("isFirstPage", pageInfo.isIsFirstPage());
		//获得总页数
		model.addAttribute("totalPages", pageInfo.getPages());
		//是否是最后一页
		model.addAttribute("isLastPage", pageInfo.isIsLastPage());
		//前台对象
		model.addAttribute("refundList", pageInfo.getList());
		model.addAttribute("completeCount", MapUtils.getObject(map,"totalAmount"));
		model.addAttribute("unCompleteCount", MapUtils.getObject(map,"refundCount"));
		//查询条件
		model.addAttribute("query",query);
		return "refundList";
	}

	@RequestMapping(value = "/detail")
	public String appealDetail(Model model, @ModelAttribute ReqRefundAdminQuery query) {
		List<RespRefundDetail> detailList = travelAppealService.selectRefundDetail(query);
		model.addAttribute("respRefundDetail", detailList.size()==0?null:detailList.get(0));
		return "refundDetail";
	}

}
